
<div class="layui-collapse">
    <form class="layui-form">
        <div class="start">
            <span class="layui-icon layui-icon-set"><h3 style="display: inline; font-size: 15px">流程表单设置</h3></span>
            <button type="button" class="layui-btn layui-btn-sm" lay-submit lay-filter="saveForm" id="saveForm">保存</button>
        </div>
        <div class="layui-colla-item upline" style="margin-bottom: 50px;">
            <h2 class="layui-colla-title line-title" style="float: right; margin-right: 50px; width: 4em">帮助</h2>
            <div class="layui-colla-content layui-show end" style="background-color: #f9f9f9;">
                <ol>
                    <li>
                        1.表单
                        <ol>
                            <li>a.在线表单，为系统自定义表单</li>
                            <li>b.url表单，是外部表单。地址写法规则为：如果表单页面平台在同一个应用中，路径从根开始写，
                            <span style="color: red">不需要上下文路径</span>，</li>
                            <li>例如：/test/baoxiao/view/modify。如果需要使用的表单不在同一个应用下，则需要写完整路径如：http://***/crm/addUser。</li>
                        </ol>
                    </li>
                    <li>
                        2.处理器
                        <ol>
                            <li>a.处理器是需要开发人员定制的，<span style="color: red">URL表单的处理器需要填写</span>。通常处理器的写法
                            是Service类名首字母小写 + "." + 方法名称。 需要注意的是这个service是需要通过spring容器管理的。</li>
                            <li>若类名称开头两个字母大写，则bean名称与类名相同。例如QJService，则bean名称即为QJService。</li>
                            <li>另外方法的参数必须是ProcessCmd类。 例如：baoxiaoService.processHandler,这个表示是BaoxiaoService类中有一个，processHandler(ProcessCmd cmd)的方法。</li>
                            <li>b.前置和后置处理器区别在于执行时机不同，前置处理器是在启动流程或完成下一步这个动作之前执行的。后置处理器在启动流程或完成下一步之后执行的。</li>
                        </ol>
                    </li>
                    <li>
                        3.URL表单授权
                        <ol>
                            <li>a.如果需要使用URL表单授权，URL必须为平台内部URL</li>
                        </ol>
                    </li>
                </ol>
            </div>
        </div>
        <div>
            <input type="hidden" name="modelId" value="${actDefModel.id}">
            <input type="hidden" name="parentProcDefId" value="${parentProcDefId}">
        </div>
        <div class="layui-colla-item upline">
            <h2 class="layui-colla-title line-title">
                全局表单
            </h2>
            <div class="select-container">
                <select name="globalFormType" lay-filter="globalFormType" class="selectFormType">
                    <#if !globalForm?? >
                        <option value="-1" selected = "selected">请选择</option>
                        <option value="0">在线表单</option>
                        <option value="1">Url表单</option>
                    </#if>
                    <#if globalForm?? >
                        <option value="-1" <#if globalForm.formType == -1>selected = "selected"</#if>>请选择</option>
                        <option value="0" <#if globalForm.formType == 0>selected = "selected"</#if>>在线表单</option>
                        <option value="1" <#if globalForm.formType == 1>selected = "selected"</#if>>Url表单</option>
                    </#if>
                </select>
            </div>
            <div class="layui-colla-content layui-show end" >
                <table class="layui-table" id="globalFormTable" style="<#if !globalForm??> display:none</#if>">
                    <tr>
                        <th>表单: &nbsp;&nbsp;</th>
                        <td>
                            <div id="globalForm" style="<#if globalForm?? && globalForm.formType != 0>display:none; </#if>">
                                <input type="hidden" class="formKey" name="defaultFormKey" id="defaultFormKey" value="${globalForm.formKey}">
                                <input type="hidden" class="formDefName" name="defaultFormName" id="defaultFormName" value="${globalForm.formDefName}">
                                <span name="spanForm" id="globalFormSpan"><a target="_blank">${globalForm.formDefName}</a></span>
                                <a class="layui-icon layui-icon-search font-small color_normal" id="selectGlobalForm">选择</a>
                                <a class="layui-icon layui-icon-close font-small color_warn clearForm" nodeId="">重选</a>
                                <a class="layui-icon layui-icon-user font-small color_normal auth" nodeId="">表单授权</a>
                                <a class="layui-icon layui-icon-help font-small color_normal tipInfo">
                                    <span hidden>设置全局表单授权，多个流程定义绑定该表单时，多个流程共用该表单的授权信息数据，
                                        倘若其他流程定义绑定该表单且需要使用不同的表单权限控制则不需要设置全局表单授权。</span>
                                </a>
                                <input type="hidden" id="globalTableId" value="${globalForm.mainTableId}">
                                <input type="hidden" id="globalExistSubTable" value="${globalForm.existSubTable}">
                                <a class="layui-icon layui-icon-user font-small color_normal " id="grantSort">子表数据排序</a>
                            </div>
                            <div id="globalFormUrl" style="<#if globalForm?? && globalForm.formType != 1>display:none; </#if>">
                                <label class="layui-form-label">表单URL:</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" name="formUrlGlobal" style="width: 88%; display: inline-block" value="${globalForm.formUrl}">
                                    <a class="layui-icon layui-icon-user font-small color_normal auth" nodeId="" style="float: right; margin-top: 10px;">URL表单授权</a>
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th>前置处理器</th>
                        <td>
                            <input class="handler layui-input" type="text" name="beforeHandlerGlobal" value="${globalForm.beforeHandler}" size="40">
                        </td>
                    </tr>
                    <tr>
                        <th>后置处理器</th>
                        <td>
                            <input class="handler layui-input" type="text" name="afterHandlerGlobal" value="${globalForm.afterHandler}" size="40">
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="layui-colla-item upline">
            <h2 class="layui-colla-title line-title" style="width: 10em">
                流程实例业务表单
            </h2>
            <div class="select-container" style="left: 170px">
                <select name="bpmFormType" id="bpmFormType" lay-filter="bpmFormType" class="selectFormType">
                    <#if !bpmForm??>
                        <option value="-1" selected="selected">请选择</option>
                        <option value="0">在线表单</option>
                        <option value="1">Url表单</option>
                    </#if>
                    <#if bpmForm??>
                        <option value="-1"  <#if bpmForm.formType == -1>selected = "selected"</#if>>请选择</option>
                        <option value="0" <#if bpmForm.formType == 0>selected = "selected"</#if>>在线表单</option>
                        <option value="1" <#if bpmForm.formType == 1>selected = "selected"</#if>>Url表单</option>
                    </#if>
                </select>
            </div>
            <div class="layui-colla-content layui-show end" >
                <div id="bpmFormContent" style="<#if ((!bpmForm??) || (bpmForm.formType != 0))> display:none</#if>">
                    表单: &nbsp;&nbsp;
                    <input type="hidden" class="formKey" name="bpmFormKey" id="bpmFormKey" value="${bpmForm.formKey}">
                    <input type="hidden" class="formDefName" name="bpmFormName" id="bpmFormName" value="${bpmForm.formDefName}">
                    <span name="spanForm" id="bpmFormSpan"><a target="_blank">${bpmForm.formDefName}</a></span>
                    <a class="layui-icon layui-icon-search font-small color_normal " id="selectBpmForm">选择</a>
                    <a class="layui-icon layui-icon-close font-small color_warn clearForm" nodeId="">重选</a>
                </div>
                <div id="bpmFormUrlContent" style="<#if ((!bpmForm??) || (bpmForm.formType != 1))> display:none</#if>">
                    <label class="layui-form-label">表单明细Url:</label>
                    <div class="layui-input-block"><input class="layui-input" type="text" name="bpmFormUrl" id="bpmFormUrl" value="${bpmForm.formUrl}"></div>
                </div>
            </div>
        </div>
        <div class="layui-colla-item upline">
            <h2 class="layui-colla-title line-title">节点表单</h2>
            <div class="layui-colla-content layui-show">
                <div class="layui-form-item" style="overflow: auto;">
                <table class="layui-table">
                    <thead>
                        <th class="center-block">节点名</th>
                        <th class="center-block"><input type="checkbox" lay-filter="jumpType" lay-skin="primary" id="ckJumpType" title="跳转类型"></th>
                        <th class="center-block">意见处理</th>
                        <th class="center-block"><input type="checkbox" lay-filter="hideAllPath" lay-skin="primary" id="ckHiddenPath" title="隐藏路径"></th>
                        <th class="center-block">处理器</th>
                        <th class="center-block">表单</th>
                    </thead>
                    <tbody>
                        <#list bpmNodeSetList as item>
                        <tr>
                            <td>
                                <input type="hidden" name="nodeId" value="${item.nodeId}">
                                <input type="hidden" name="nodeNames" value="${item.nodeName}">
                                ${item.nodeName}
                            </td>
                            <td>
                                <div class="center-block" style="width: 117px;">
                                    <input type="checkbox" class="jumpTypeItem" lay-filter="jumpTypeItem" lay-skin="primary" name="jumpType_${item.nodeId}" <#if item.jumpType?index_of('1') != -1>checked</#if> value="1" title="正常跳转" />
                                    <input type="checkbox" class="jumpTypeItem" lay-filter="jumpTypeItem" lay-skin="primary" name="jumpType_${item.nodeId}" <#if item.jumpType?index_of('2') != -1>checked</#if> value="2" title="选择路径跳转"/>
                                    <input type="checkbox" class="jumpTypeItem" lay-filter="jumpTypeItem" lay-skin="primary" name="jumpType_${item.nodeId}" <#if item.jumpType?index_of('3') != -1>checked</#if> value="3" title="自由跳转"/>
                                </div>
                            </td>
                            <td>
                                <div class="center-block">
                                <div class="center-blocker">
                                    <input type="checkbox" lay-skin="primary"  class="isRequired" name="isRequired_${item.nodeId}" <#if item.isRequired == 1>checked</#if> <#if item.isHideOption==1>disabled </#if> value="1" title="是否必填" />
                                    <input type="checkbox" lay-skin="primary" class="isPopup" name="isPopup_${item.nodeId}" <#if item.isPopup == 1>checked</#if> <#if item.isHideOption==1>disabled </#if> value="1" title="是否弹窗" />
                                    <input type="checkbox" lay-skin="primary"  class="canUploadFile" name="canUploadFile_${item.nodeId}" <#if item.canUploadFile == 1>checked</#if> <#if item.isHideOption==1>disabled </#if> value="1" title="是否允许上传附件" />
                                    <input lay-filter="isHideOption" type="checkbox" lay-skin="primary"  class="isHideOption" name="isHideOption_${item.nodeId}" <#if item.isHideOption == 1>checked</#if> value="1" title="是否隐藏意见表单" />
                                    <div style="margin: 7px;">
                                        <input class="layui-input" type="text" name="opinionField_${item.nodeId}" id="opinionField_${item.nodeId}" value="${item.opinionField }" style="height: 25px;line-height: 25px;" readonly="readonly"/>
                                        <a class="showField" nodeId="${item.nodeId}" style="cursor: pointer">意见回填字段</a>
                                        <a class="clearField" nodeId="${item.nodeId}" lay-filter="clearField" style="cursor: pointer">清除</a>
                                    </div>
                                </div>
                                </div>
                            </td>
                            <td>
                                <div class="center-block">
                                <input type="checkbox" lay-skin="primary" lay-filter="hidePath" class="hidePath" name="isHidePath_${item.nodeId}" <#if item.isHidePath == 1>checked</#if> value="1"  />
                                </div>
                            </td>

                            <td>
                                <table class="layui-table" style="min-width: 280px;">
                                    <tr>
                                        <td nowrap="nowrap" class="head">前置:</td>
                                        <td><input class="handler layui-input" type="text" name="beforeHandler" value="${item.beforeHandler}" size="20"/>

                                        </td>
                                    </tr>
                                    <tr>
                                        <td nowrap="nowrap" class="head">后置:</td>
                                        <td><input class="handler layui-input" type="text" name="afterHandler" value="${item.afterHandler}" size="20"/>

                                        </td>
                                    </tr>
                                </table>
                            </td>

                            <td class='formBox'>
                                <input id="nodeId" type ="hidden" value="${item.nodeId}"/>
                                <table class="layui-table" style="min-width: 280px;" >
                                    <tr>
                                        <td nowrap="nowrap" class="head">表单类型:</td>
                                        <td>
                                            <select lay-filter="nodeFormType" nodeId="${item.nodeId}" name="formType" class="selectNodeForm" >
                                                <option value="-1" <#if item.formType == -1>selected = "selected"</#if>>请选择..</option>
                                                <option value="0" <#if item.formType == 0>selected = "selected"</#if>>在线表单</option>
                                                <option value="1"<#if item.formType == 1>selected = "selected"</#if>>URL表单</option>
                                            </select>
                                        </td>
                                    </tr>
                                </table>
                                <div id="formBox_${item.nodeId}" name="nodeForm" >
                                    <table class="layui-table " >
                                        <tr class="form_${item.nodeId}" style="<#if item.formType == -1> display:none</#if>">
                                            <th>表单: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
                                            <td>
                                                <div id="nodeForm_${item.nodeId}" style="<#if item.formType!=0>display:none</#if>">
                                                    <input type="hidden" class="formKey" name="formKey" value="${item.formKey}">
                                                    <input type="hidden" class="oldFormKey" name="oldFormKey" value="${item.formKey}">
                                                    <input type="hidden" class="formDefName" name="formDefName" value="${item.formDefName}">
                                                    <input type="hidden" class="tableId" name="tableId" value="${item.mainTableId }">
                                                    <span name="spanForm" class="nodeFormSpan"><a target="_blank">${item.formDefName}</a></span>
                                                    <a class="layui-icon layui-icon-search font-small color_normal selectedNodeForm">选择</a>
                                                    <a class="layui-icon layui-icon-close font-small color_warn clearForm" nodeId="${item.nodeId}">重选</a>
                                                    <a class="layui-icon layui-icon-user font-small color_normal auth" nodeId="${item.nodeId}">表单授权</a>
                                                    <input type="hidden" class="existSubTable" value="${item.existSubTable }">
                                                    <a class="layui-icon layui-icon-user font-small color_normal grant" nodeId="${item.nodeId}" >子表数据授权</a>
                                                </div>
                                                <div name="nodeFormUrl" id="nodeFormUrl_${item.nodeId}" style="<#if item.formType!=1>display:none</#if>">
                                                    <label class="layui-form-label" style="width: 40%;padding: 9px 0;text-align: center;">表单URL：</label>
                                                    <div class="layui-input-inline" style="width: 60%;margin: 0;">
                                                        <input class="layui-input" type="text"  name="formUrl" style="width: 100%" value="${item.formUrl}">
                                                    </div>
                                                    <br/>
                                                    <a class="layui-icon layui-icon-user font-small color_normal auth" nodeId="${item.nodeId}">URL表单授权</a>
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </td>
                        </tr>
                        </#list>
                    </tbody>
                </table>
                </div>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['element', 'table', 'setter', 'util', 'form','layer','jquery', 'commons'], function () {
        var element = layui.element,
            table=layui.table,
            form = layui.form,
            $ = layui.jquery,
            setter = layui.setter,
            commons = layui.commons,
            totalFilter = layui.totalFilter,
            layer = layui.layer;

        element.render();
        form.render();
        table.render();
        var modelId = '${actDefModel.id}';
        var procDefId = '${actDefModel.procDefId}';
        var parentProcDefId = '${parentProcDefId}';

        var globalExistSubTable =$('#globalExistSubTable').val();
        if(globalExistSubTable == null||globalExistSubTable==0){
            $("#grantSort").hide();
        }

        $('.existSubTable').each(function(){
            var obj = $(this);
            if(obj.val()==0){
                obj.siblings("a.grant").hide();
            }
        });

        form.on('checkbox(isHideOption)', function(data){
            if (data.elem.checked==true){
                $(data.elem).prevAll("input").removeAttr("checked").attr("disabled", "true");
            }else {
                $(data.elem).prevAll("input").removeAttr("disabled");
            }
            form.render();
        });
        //是否默认选中  隐藏执行路径
        var isNew = '${isNew}';
        if(isNew=='yes'){             //没有绑定表单时都要默认选中  隐藏执行路径
            $('#ckHiddenPath').attr('checked',true);
            $('.hidePath').attr('checked',true);
            form.render('checkbox');
        }

        form.on('submit(saveForm)', function (data) {
            var bpmFormType = $("#bpmFormType").val();
            var isEmpty = isEmptyForm();
            if (!isEmpty) {
                if (bpmFormType == -1) {
                    layer.msg("请设置流程实例业务表单");
                    return;
                }else if (bpmFormType == 0) {
                    var bpmFormKey = $("#bpmFormKey").val();
                    if(!bpmFormKey||bpmFormKey==0){
                        layer.msg("请设置流程实例业务表单");
                        return;
                    }
                }else if (bpmFormType == -1) {
                    var bpmFormUrl=$("#bpmFormUrl").val();
                    if(!bpmFormUrl||bpmFormUrl==''){
                        layer.msg("请设置流程实例业务表单");
                        return;
                    }
                }
            }
            $.ajax({
                method: "post",
                dataType: "json",
                data: $(data.form).serialize(),
                url: "${ctx}/workflow/bpmNodeSet/save",
                success: function (result) {

                    if (commons._filterRecord(result)) {
                        parent.layer.alert(result.msg, function (index) {
                            parent.layer.close(index);
                        })
                    } else {
                        window.parent.layer.alert(result.msg);
                    }
                }
            });

        });


        function isEmptyForm() {
            var isEmpty = true;
            var globalFormObj = $("div[name='globalFormUrl']");
            var globalUrlObj=globalFormObj.find('input[name="formUrlGlobal"]');
            var globalUrl=(globalUrlObj!=undefined)?globalUrlObj.val():"";
            var globalFormKey=($("#defaultFormKey")!=undefined)?$("#defaultFormKey").val():0;
            if(globalUrl!=""||globalFormKey!=0){
                isEmpty=false;
            }

            $("div[name='nodeForm']").each(function(){
                var formKeyObj=$(this).find('input[name="formKey"]');
                var formKey=(formKeyObj!=undefined)?formKeyObj.val():0;
                var formUrlObj=$(this).find('input[name="formUrl"]');
                var formUrl=(formUrlObj!=undefined)?formUrlObj.val():"";
                if(formKey!=0||formUrl!=""){
                    isEmpty=false;
                }
            });
            return isEmpty;
        }

        //表单授权
        $(".auth").click(function () {
            var platform = 0;
            var nodeId = $(this).attr("nodeId");
            var tdObj = $(this).parent();
            var objDefId = $("input.formKey", tdObj);

            if (objDefId.val() == "" || objDefId.val() == 0) {
                layer.msg("请先选择表单");
                return;
            }

            var formKey = objDefId.val();
            if (formKey == undefined) {
                formKey = $("input[name='formUrlGlobal']").val();
                if (nodeId != '') {
                    formKey = $("input[name='formUrl']",tdObj).val();
                }

                if (formKey.indexOf("?") !== -1) {
                    formKey = formKey.substring(0, formKey.indexOf("?"));
                }
            }

            var url = serverPath.formPath + setter.formLinkPath +"formDef/view/formPermission?procDefId="
                + procDefId + "&formKey=" + formKey + "&nodeId=" + nodeId +"&platform="+platform;

            if (parentProcDefId) {
                url += "&parentProcDefId=" + parentProcDefId;
            }

            layer.open({
                type: 2,
                title: "表单授权",
                shade: 0.3,
                area: ['1000px', '620px'],
                content: url
            });

        });

        // 重选
        $(".clearForm").click(function () {

            var tdObj = $(this).parent();
            var platform = 0;
            var formKey = $("input.formKey", tdObj).val();
            var nodeId = $(this).attr("nodeId");

            layer.confirm("确定重选?重选会清空表单授权信息！", function (index) {
                url = serverPath.formPath + setter.formLinkPath +"formDef/resetPermission";
                $.ajax({
                    type: "post",
                    dataType: "json",
                    url: url,
                    data: {formKey:formKey,actDefId:procDefId,nodeId:nodeId,parentActDefId:parentProcDefId,platform:platform},
                    success: function (result) {
                        if (commons._filterRecord(result)) {
                            $("input.formKey",tdObj).val('');
                            $("input.formDefName",tdObj).val('');
                            $("span[name='spanForm']",tdObj).text('');
                            $(this).siblings("a.grant").hide();
                            $(this).siblings("a.grantSort").hide();
                            layer.close(index);
                        } else {
                            window.parent.layer.alert(result.msg);
                        }
                    }
                });

            });
        });

        // 全局与实例下拉框联动
        form.on('select(globalFormType)', function (data) {
            var selectedValue = data.value;
            if (selectedValue == -1) {
                $("#globalFormTable").hide();
                $("#bpmFormType").val(-1);
                $("#bpmFormContent").hide();
                $("#bpmFormUrlContent").hide();
            } else {
                $("#globalFormTable").show();
                if (selectedValue == 0) {
                    $("#globalFormUrl").hide();
                    $("#globalForm").show();
                    $("#bpmFormType").val(0);
                    $("#bpmFormContent").show();
                    $("#bpmFormUrlContent").hide();
                } else if (selectedValue == 1) {
                    $("#globalForm").hide();
                    $("#globalFormUrl").show();
                    $("#bpmFormType").val(1);
                    $("#bpmFormContent").hide();
                    $("#bpmFormUrlContent").show();
                }
            }
            form.render();
        });

        form.on('select(bpmFormType)', function (data) {
            var selectedValue = data.value;
            if (selectedValue == -1) {
                $("#bpmFormContent").hide();
                $("#bpmFormUrlContent").hide();
            } else if (selectedValue == 0) {
                $("#bpmFormContent").show();
                $("#bpmFormUrlContent").hide();

            } else if (selectedValue == 1) {
                $("#bpmFormContent").hide();
                $("#bpmFormUrlContent").show();

            }
        });

        form.on('select(nodeFormType)', function (data) {
            var nodeId = data.elem.getAttribute('nodeId');
            var selectedValue = data.value;
            if (selectedValue == -1) {
                $(".form_" + nodeId).hide();
                $("#nodeForm_" + nodeId).hide();
                $("#nodeFormUrl_" + nodeId).hide();
            }else if(selectedValue == 0){
                $(".form_" + nodeId).show();
                $("#nodeForm_" + nodeId).show();
                $("#nodeFormUrl_" + nodeId).hide();

            }else if (selectedValue == 1) {
                $(".form_" + nodeId).show();
                $("#nodeForm_" + nodeId).hide();
                $("#nodeFormUrl_" + nodeId).show();

            }

        });


        // 全选
        form.on('checkbox(hideAllPath)', function (data) {
            var check = data.elem.checked;
            if (check) {
                $(".hidePath").prop("checked", true);
                form.render('checkbox');
            } else {
                $(".hidePath").prop("checked", false);
                form.render('checkbox');
            }

        });

        form.on('checkbox(jumpType)', function (data) {
            var check = data.elem.checked;
            if (check) {
                $(".jumpTypeItem").prop("checked", true);
                form.render('checkbox');
            } else {
                $(".jumpTypeItem").prop("checked", false);
                form.render('checkbox');
            }

        });

        //有一个未选中全选取消选中
        form.on('checkbox(hidePath)', function (data) {
            var item = $(".hidePath");
            for (var i = 0; i < item.length; i++) {
                if (item[i].checked == false) {
                    $("#ckHiddenPath").prop("checked", false);
                    form.render('checkbox');
                    break;
                }
            }
            //如果都勾选了  勾上全选
            var  all=item.length;
            for (var i = 0; i < item.length; i++) {
                if (item[i].checked) {
                    all--;
                }
            }
            if(all==0){
                $("#ckHiddenPath").prop("checked", true);
                form.render('checkbox');}
        });

        form.on('checkbox(jumpTypeItem)', function (data) {
            var item = $(".jumpTypeItem");
            for (var i = 0; i < item.length; i++) {
                if (item[i].checked == false) {
                    $("#ckJumpType").prop("checked", false);
                    form.render('checkbox');
                    break;
                }
            }
            //如果都勾选了  勾上全选
            var  all=item.length;
            for (var i = 0; i < item.length; i++) {
                if (item[i].checked) {
                    all--;
                }
            }
            if(all==0){
                $("#ckJumpType").prop("checked", true);
                form.render('checkbox');}
        });

        // 前置后置处理器验证
        $("input.handler").blur(function(){
            var obj=$(this);
            var val=obj.val();
            if(val.trim()==""){
                return;
            }
            var params={handler:val};
            $.ajax({
                method: "post",
                data:params,
                dataType: "json",
                url:serverPath.workflowPath + "/workflow/bpmNodeSet/validHandler",
                success: function (data) {
                    if (data.code != 0) {
                        layer.msg(data.msg,function () {
                            obj.focus();
                        })
                    }
                }
            });

        });

        var formType;

        // 选择全局表单
        $("#selectGlobalForm").click(function () {
            formType = '0';
            openFormWindow(formType);
        });

        // 选择实例表单
        $("#selectBpmForm").click(function () {
            formType = '1';
            openFormWindow(formType);

        });

        var tdObj;

        // 选择节点表单
        $(".selectedNodeForm").click(function () {
            tdObj = $(this).parent();
            formType = '2';
            openFormWindow(formType);

        });

        function openFormWindow(formType) {
            layer.open({
                type: 2,
                area: ['760px','630px'],
                title: ['选择表单'],
                content:serverPath.formPath + setter.formLinkPath +  'formDef/view/formSelector?formType=' + formType
            });

        }

        window.setGlobalFormValue = function (formDefId, formSubject, formDefKey, tableId) {
            $("#defaultFormKey").val(formDefKey);
            $("#bpmFormKey").val(formDefKey);
            $("#defaultFormName").val(formSubject);
            $("#bpmFormName").val(formSubject);
            $("#globalTableId").val(tableId);
            //给表单添加 超链接，使之能看到表单明细
            var namesUrl="<a target='_blank' href='' >"+formSubject+"</a>";
            $("#globalFormSpan").html(namesUrl);
            $("#bpmFormSpan").html(namesUrl);

            // 是否显示子表数据排序按钮
            $.ajax({
                url: serverPath.formPath + "/form/table/hasSubTable?formKey=" + formDefKey,
                method:"post",
                dataType: "json",
                success:function (result) {
                    if (result.code != 0) {
                        $("#grantSort").hide();
                    }else{
                        $("#grantSort").show();
                    }
                }
            });

        };

        window.setBpmFormValue = function (formDefId, formSubject, formDefKey, tableId) {
            $("#bpmFormKey").val(formDefKey);
            $("#bpmFormName").val(formSubject);
            //给表单添加 超链接，使之能看到表单明细
            var namesUrl="<a target='_blank' href='' >"+formSubject+"</a>";
            $("#bpmFormSpan").html(namesUrl);
        };

        window.setNodeFormValue = function (formDefId, formSubject, formDefKey, tableId) {
            $("input.formKey",tdObj).val(formDefKey);
            $("input.formDefName",tdObj).val(formSubject);
            $("input.tableId",tdObj).val(tableId);
            //给表单添加 超链接，使之能看到表单明细
            var namesUrl="<a target='_blank' href='' >"+formSubject+"</a>";
            $(".nodeFormSpan",tdObj).html(namesUrl);

            // 是否显示子表数据授权按钮
            $.ajax({
                url: serverPath.formPath + "/form/table/hasSubTable?formKey=" + formDefKey,
                method:"post",
                dataType: "json",
                success:function (result) {
                    if (result.code != 0) {
                        $(tdObj).find("a.grant").hide();
                    }else{
                        $(tdObj).find("a.grant").show();
                    }
                }
            });
        };

        // 意见回填字段

        var tmpNodeId;
        $(".showField").click(function () {
            tmpNodeId = $(this).attr("nodeId");
            var formKey = $("#defaultFormKey").val();
            if (formKey == null || formKey == "") {
                layer.msg("请先选择全局在线表单");
                return;
            }

            layer.open({
                type: 2,
                area: ['760px','630px'],
                title: ['字段选择'],
                content: serverPath.formPath + setter.formLinkPath+ 'formDef/view/fieldDialog?formKey=' + formKey
            });
        });

        $(".clearField").click(function () {
            var nodeId = $(this).attr("nodeId");
            $("#opinionField_" + nodeId).val("");
        });

        $("a.tipInfo").mouseover(function(){

            var text = $("span",$(this)).text();

            layer.tips(text, 'a.tipInfo', {
                tips:[1,'#3595CC'],
                time:3000
            });
        });


        window.setFieldName = function (fieldName) {
            $("#opinionField_" + tmpNodeId).val(fieldName);
        }


        $(".grant").click(function () {
            var nodeId = $(this).attr("nodeId");
            var btn=$(this);
            var tdObj=btn.parent();
            var objDefId=$("input.formKey",tdObj);
            var formKey=objDefId.val();
            var tableId = $("input.tableId",tdObj).val();
            var url= serverPath.formPath + setter.formLinkPath+ 'formDef/view/subRightsDialog?procDefId='
                + procDefId +'&nodeId=' + nodeId +'&formKey=' + formKey+'&tableId='+tableId;
            if(parentProcDefId){
                url += "&parentProcDefId=" + parentProcDefId;
            }

            layer.open({
                type: 2,
                area: ['800px','630px'],
                title: ['子表数据授权'],
                content: url
            });
        })

    });
</script>
